package com.ddwl.user.controller;


import com.ddwl.common.annotation.Auth;
import com.ddwl.common.constant.BaseEnum;
import com.ddwl.common.controller.BaseController;
import com.ddwl.schema.bo.user.ChildrenBo;
import com.ddwl.schema.vo.base.RestVo;
import com.ddwl.schema.vo.user.ChildrenVo;
import com.ddwl.user.service.ChildrenService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @author Fu Zhaohui
 * @date 2017/2/5
 */
@Api(tags = "小孩管理服务")
@Auth(product = {BaseEnum.ProductEnum.CLOTHES, BaseEnum.ProductEnum.MALL})
@RequestMapping("/children")
@RestController
public class ChildrenController extends BaseController {

    @Autowired
    private ChildrenService childrenService;

    @GetMapping
    @Auth
    @ApiOperation("我的小孩")
    public RestVo<List<ChildrenVo>> getByUser() {
        return RestVo.ok(childrenService.getByUser(getUserId()));
    }

    @PostMapping("create")
    @ApiOperation("保存小孩")
    public RestVo create(@Valid @RequestBody ChildrenBo bo) {
        bo.setUserId(getUserId());
        childrenService.create(bo);
        return RestVo.ok();
    }

    @PostMapping("update")
    @ApiOperation("保存小孩")
    public RestVo update(@Valid @RequestBody ChildrenBo bo) {
        bo.setUserId(getUserId());
        childrenService.create(bo);
        return RestVo.ok();
    }
}
